<?php
require_once 'BaseController.php';

/**
 * 【PC版】町名選択 コントローラ
 */
class Renew_TownController extends Renew_BaseController
{

    /**
     * メインアクション
     */
    public function indexAction()
    {
        $params = $this->getParameters();
    }

    public function postAction()
    {
        $params = $this->getParameters();

        $cat = $params['search_type'];

        if ($params['SrhKbn'] == '11')
        {
            if ($params['target_0'])
            {
                $this->getPrefData($params['target_0']);
            }
            else
            {
                $this->getPrefData($params['PrefCd'][0] . "-" . $params['CityCd'][0]);
            }
        }
        else
        {
            $this->getPrefData($params['target_0']);
        }

        $model = new Search_Model_Selareasearch();
        $selCity = array();
        foreach ($params as $key => $value)
        {
            if (strpos($key, 'target_') !== false)
            {
                $selCity[] = substr($value, 5);
            }
        }
        $params['cityCds'] = "'" . implode("','", $selCity) . "'";
        $params['prefCd'] = $this->_data['PrefCd'];
        $data = $model->getChouList($params);

        $selCity = array();
        foreach ($data as $d)
        {
            $shiku = $d['SHIKUCHOUSON_CD'];

            if (array_key_exists($shiku, $selCity) == false)
            {
                $selCity["$shiku"]['SHIKUCHOUSON'] = $d['SHIKUCHOUSON'];
                $selCity["$shiku"]['CHOU_DATA'] = array();
            }
            $selCity["$shiku"]['CHOU_DATA'][] = array(
                'TODOUFUKEN_CD' => $d['TODOUFUKEN_CD'],
                'SHIKUCHOUSON_CD' => $d['SHIKUCHOUSON_CD'],
                'CHOUMEI' => $d['CHOUMEI'],
                'CHOUMEI_CD' => $d['CHOUMEI_CD'],
                'CHOUMEI_CNT' => $d['CHOUMEI_CNT']
            );
        }
        $this->_data['selCityTitle'] = reset($selCity);

        $this->_data['selCity'] = $selCity;

        $this->_data['Mapping_params'] = $params;

        $this->displayBody2('index');
    }

    public function getPrefData($code)
    {
        $model = new Search_Model_Selareasearch();
        $c = substr($code, 0, 2);
        $this->_data['PrefCd'] = $c;
        $this->_data['PrefInfo'] = $model->getSimpleArea($c);
        $this->_data['PrefName'] = $this->getPrefName($c);
        $this->_data['PrefNameJP'] = $this->getPrefNameJP($c);
        $this->_data['PrefNameJPWithoutPostfix'] = $this->getPrefNameWithoutPostfix($this->_data['PrefNameJP']);
    }

    /**
     * SEO対策用のmetaタグに配置する文章を設定
     */
    protected function setSeoMeta()
    {
        $city = $this->_data['selCityTitle']["SHIKUCHOUSON"];

        $this->_meta_title = $city . 'の賃貸情報 【アパマンショップ】';
        $this->_meta_description = $city . 'の町名からお部屋を探すなら、不動産情報が満載のアパマンショップネットワーク。賃貸マンション・アパートなど、';
        $this->_meta_keywords = $city . ' 賃貸,';
    }

}

?>